package com.bw.controller;

import com.bw.bean.Student2Bean;
import com.bw.bean.Type2Bean;
import com.bw.service.InService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class Icontroller {

    @Resource
    private InService inService;

    @RequestMapping("list")
    public String getlist(Model model, @RequestParam(defaultValue = "1")Integer pageNum,@RequestParam(defaultValue = "")String sname){
        PageHelper.startPage(pageNum,10);
        Map map = new HashMap();
        map.put("sname",sname);
        List<Student2Bean> list = inService.list(map);
        PageInfo pageInfo = new PageInfo(list);
        model.addAttribute("plist",pageInfo);
        model.addAttribute("sname",sname);
        return "list";
    }

    @RequestMapping("del")
    @ResponseBody
    public int getdel(Integer sid){
        int del = inService.del(sid);
        return del;
    }

    @RequestMapping("add")
    public String getadd(Student2Bean student2Bean){
        int add = inService.add(student2Bean);
        return "redirect:list";
    }
    @RequestMapping("huixian")
    @ResponseBody
    public List<Type2Bean> gethuixian(){
        List<Type2Bean> huixian = inService.huixian();
        System.out.println(huixian);
        return huixian;
    }
    @RequestMapping("update")
    public String getupdate(Student2Bean student2Bean){
        int update = inService.update(student2Bean);
        return "redirect:list";
    }
    @RequestMapping("idlist")
    @ResponseBody
    public Student2Bean getidlist(Integer sid){
        System.out.println(sid);
        Student2Bean idlist = inService.idlist(sid);
        System.out.println(idlist);
        return idlist;
    }
}
